<template>
    <div class="versiuo_info_list">
        <div v-for="item in version" :title="`${item.name}:${item.version}`">{{ item.name }} : {{ item.version }}</div>
        <div> 编辑器打包时间：{{ lastBuildTime }}</div>
    </div>
</template>
<script setup lang="ts">
import { inject, onMounted, onBeforeUnmount, ref, computed } from "vue";

import { getProjectManager } from '@/scripts/getProjectManager';
import { ESUeViewer } from "earthsdk3-ue";

const lastBuildTime = computed(() => import.meta.env.VITE_APP_LAST_BUILD_TIME)

const obj = getProjectManager()
const version = ref<{ name: string, version: string }[]>([])
function getValueBeforeFirstComma(str: string) {
    var parts = str.split('  ');
    return parts[0];
}
function getValueBeforeFirstComma2(str: string) {
    var parts = str.split('  ');
    return parts[1];
}
const getVersion = async () => {
    const viewer = obj.activeViewer
    if (!viewer) return
    const v: any = []
    const versions = await viewer.getVersion()
    if (!versions) return
    for (let key in versions) {
        if (versions.hasOwnProperty(key)) { // 确保是对象自有属性，不是原型链上的属性
            if (key === 'esforue') {
                if (viewer instanceof ESUeViewer) {
                    v.push({ name: getValueBeforeFirstComma(versions[key]), version: getValueBeforeFirstComma2(versions[key]) })
                }
            } else {
                v.push({ name: key, version: versions[key].version ? versions[key].version : versions[key] })
            }
        }
    }
    // @ts-ignore
    version.value = v
}
onMounted(() => {
    getVersion()
})
</script>
<style scoped>
.versiuo_info_list {
    position: fixed;
    right: 5px;
    bottom: 35px;
    min-width: 200px;
    max-width: 300px;
    /* height: 200px; */
    background: #fff;
    z-index: 200;
    border: 1px solid rgba(180, 180, 180, 1);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    border-radius: 5px;
    padding: 3px 10px;
    color: black;
}

.versiuo_info_list>div {
    width: 100%;
    height: 25px;
    line-height: 25px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}
</style>